import 'package:FineArt/constants.dart';
import 'package:FineArt/core/widget/list/notice_item.dart';
import 'package:FineArt/utils/size_config.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:FineArt/core/api/notice_api.dart';

//通知列表
class NoticeListPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _NoticesPageState();
  }
}

class _NoticesPageState extends State<NoticeListPage> {
  List<NoticeItemResp> data = [];
  int lastId = 0;

  @override
  void initState() {
    super.initState();
    _loadNotice();
  }

  _loadNotice() {
    NoticeApi().getNoticeList(lastId, 100).then((res) {
      if (res.code == 200) {
        setState(() {
          data = res.data.list;
        });

      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          shadowColor: Colors.transparent,
          title: Text(
            "我的通知",
            style: TextStyle(color: text_black, fontSize: setSp(18)),
          ),
          centerTitle: true,
          backgroundColor: Colors.white,
          brightness: Brightness.light,
          toolbarHeight: getPortraitSHeight(40),
          leading: IconButton(
              alignment: Alignment.centerLeft,
              icon: Image.asset(
                "assets/images/icon_back_black.png",
                width: getPortraitSWidth(11),
                height: getPortraitSHeight(18),
              ),
              onPressed: () {
                Navigator.of(context).pop();
              })),
      body: SafeArea(
        child: _widget_refresh_list(),
      ),
    );
  }

  EasyRefreshController _controller = EasyRefreshController();

  Widget _widget_refresh_list() {
    double width = MediaQuery.of(context).size.width * 0.98;
    MaterialHeader header =
        MaterialHeader(completeDuration: new Duration(milliseconds: 100));
    return EasyRefresh.custom(
      controller: _controller,
      header: header,
      footer: MaterialFooter(),
      onRefresh: () async {},
      onLoad: () async {
        // _nextPage(widget.currentPath, widget.currentFilter);
      },
      slivers: <Widget>[
        // SliverToBoxAdapter(
        //   child: _playHeaderCol(isTeacher),
        // ),
        SliverPadding(
            padding: EdgeInsets.only(left: 3, right: 3),
            sliver: SliverList(
              delegate: SliverChildBuilderDelegate(
                (BuildContext context, int index) {
                  //创建子widget
                  // var resource = resources[index];
                  return NoticeItemView(
                    title: data[index].type,
                    isRead: true,
                    date: data[index].createdAt.split("T")[0],
                    content: data[index].content,
                  );
                },
                childCount: data.length,
              ),
            )),

        //=====列表=====//
      ],
    );
  }
}
